export function formatTimestamp(timestamp: number) {
    if(!timestamp) return '暂无数据'
    // 如果是秒级时间戳（10位），转换为毫秒级
    if (String(timestamp).length === 10) {
        timestamp *= 1000;
    }

    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = date.getMonth() + 1; // 月份从 0 开始，需要 +1
    const day = date.getDate();

    const formattedMonth = month < 10 ? `0${month}` : `${month}`;
    const formattedDay = day < 10 ? `0${day}` : `${day}`;
    return `${year}-${formattedMonth}-${formattedDay}`;
}

export function getStorage(key: string) {
    return new Promise((resolve, reject) => {
        wx.getStorage({
            key,
            success: (res) => resolve(res.data), // 返回存储的值
            fail: (err) => reject(err),         // 返回错误信息
        });
    });
}

export const env = {
    API_BASE_URL: "https://www.kdjl.asia:3000"
}

export const findEmptyKeys = <T extends Record<string, any>>(obj: T): string[] => {
    return Object.keys(obj).filter(key => obj[key] === '');
}

export const ZT = ''

